// File:    TnExToolsSpatial.cs
// Author:  HT
// Created: Tuesday, October 18, 2011 3:49:03 PM
// Purpose: Definition of Class TnExToolsSpatial

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.DataSourcesGDB;

namespace Tayninh2011
{
    public class TnExToolsSpatial : TnExtensionTools, ITnExToolsSpatial
    {
        //constructor
        public TnExToolsSpatial()
        {
            this.name = "tool spatial";
            
        }
        public string TnBuffer(string in_features, string out_feature, object distance, string environment, IWorkspaceEdit workspace)
        {
            try
            {
                Geoprocessor gp = new Geoprocessor();

                ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();

                gp.SetEnvironmentValue("workspace", environment);
                bufferTool.in_features = in_features;
                bufferTool.out_feature_class = this.Mem4DataManager.TempFullPath + out_feature;
                bufferTool.buffer_distance_or_field = distance;
                runTool(gp, bufferTool, null);
            }
            catch (Exception err) { MessageBox.Show("loi buffer: " + err.ToString()); }

            return this.Mem4DataManager.TempFullPathNoEnd;
        }

        public string TnBuffer(string in_features, string out_feature, object distance,out string out_path, string environment, IWorkspaceEdit workspace)
        {
            try
            {
                Geoprocessor gp = new Geoprocessor();

                ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();

                gp.SetEnvironmentValue("workspace", environment);
                bufferTool.in_features = in_features;//"Database Connections/Connection to HT-LAPTOP.sde" +"/"+ in_features;
                
                //van chua hieu tai sao phai chen "tn" o giua, ko thi no ko chiu thuc hien buffer
                bufferTool.out_feature_class = this.Mem4DataManager.TempFullPath+"tn" + out_feature;
                bufferTool.buffer_distance_or_field = distance;
                //runTool(gp, bufferTool, null);
                gp.Execute(bufferTool, null);
            }
            catch (Exception err) { MessageBox.Show("loi buffer: " + err.ToString()); }
            out_path = this.Mem4DataManager.TempFullPathNoEnd;
            return "tn"+out_feature;
        }

        public string TnBuffer(string in_features, string out_feature, object distance, IWorkspaceEdit workspace)
        {
            try
            {
                Geoprocessor gp = new Geoprocessor();

                ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();

                gp.SetEnvironmentValue("workspace", this.Mem4DataManager.TempFullPathNoEnd);
                bufferTool.in_features = in_features;
                bufferTool.out_feature_class = this.Mem4DataManager.TempFullPath + out_feature;
                bufferTool.buffer_distance_or_field = distance;
                runTool(gp, bufferTool, null);
            }
            catch (Exception err) { MessageBox.Show("loi buffer: " + err.ToString()); }

            return this.Mem4DataManager.TempFullPathNoEnd;
        }

        public void TnClip(string in_feature, string clip_feature, string out_feature, string environment)
        {
            try
            {
                Geoprocessor gp = new Geoprocessor();
                ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();
                IVariantArray param = new VarArrayClass();
                gp.SetEnvironmentValue("workspace", environment);
                clipTool.in_features = in_feature;
                clipTool.clip_features = clip_feature;
                clipTool.out_feature_class = this.Mem4DataManager.TempFullPath + out_feature;//"C:\\tayninh\\temp\\tempmdb.mdb\\" + out_feature;

                runTool(gp, clipTool, null);
            }
            catch (Exception err) { MessageBox.Show("loi clip: " + err.ToString()); }
        }

       

    }
}
